using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace Umbraco.Ecommerce.StoreAdminstration
{
	/// <summary>
	/// Summary description for controlpanel.
	/// </summary>
	public class ControlPanel : umbraco.BasePages.UmbracoEnsuredPage
	{
		protected umbraco.uicontrols.CodeArea TemplateBody;
		protected umbraco.uicontrols.TabView TabView1;
		protected umbraco.uicontrols.Pane Panel2;
		protected umbraco.uicontrols.Pane Panel1;
		public umbraco.uicontrols.TabPage EditShopEmailXsl;
		protected umbraco.uicontrols.CodeArea EmailOutput;
		protected umbraco.uicontrols.CodeArea XslBody;
		protected System.Web.UI.WebControls.TextBox orderid;
		
		protected umbraco.uicontrols.Pane Pane1;
		public umbraco.uicontrols.TabPage EditShopConfig;
		protected System.Web.UI.WebControls.Button test;
		protected System.Web.UI.WebControls.TextBox query;
		protected System.Web.UI.WebControls.Button querysettingsfile;
		protected umbraco.uicontrols.CodeArea QueryResult;
		protected umbraco.uicontrols.Pane Pane2;
		public umbraco.uicontrols.TabPage EmailOutputtab;
		public umbraco.uicontrols.TabPage QuerySettingFileTab;

		private void Page_Load(object sender, System.EventArgs e)
		{
			if (!IsPostBack)
			{
				TemplateBody.Text = BusinessLogic.Store.ConfigurationXmlContent;
				XslBody.Text = BusinessLogic.Store.EmailXslContent;
		
			}

			else 
			{
				if (BusinessLogic.Store.ConfigurationXmlContent != TemplateBody.Text)
					BusinessLogic.Store.ConfigurationXmlContent = TemplateBody.Text;
				if (XslBody.Text != BusinessLogic.Store.EmailXslContent)
					BusinessLogic.Store.EmailXslContent = XslBody.Text;
			}

		}
		
		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);

			EditShopConfig = TabView1.NewTabPage("Eshop configuration");
			EditShopConfig.Controls.Add(Panel1);
			EditShopEmailXsl = TabView1.NewTabPage("Eshop email xsl transformation");
			EditShopEmailXsl.Controls.Add(Panel2);
			
			EmailOutputtab = TabView1.NewTabPage("Eshop email output");
			EmailOutputtab.Controls.Add(Pane1);

			QuerySettingFileTab = TabView1.NewTabPage("Query settingsfile");
			QuerySettingFileTab.Controls.Add(Pane2);


			ImageButton save = EditShopConfig.Menu.NewImageButton();
			save.ImageUrl = umbraco.GlobalSettings.Path +"/images/editor/save.gif";
			ImageButton save2 = EditShopEmailXsl.Menu.NewImageButton();
			save2.ImageUrl = umbraco.GlobalSettings.Path +"/images/editor/save.gif";

			
			
			EditShopConfig.Style.Add("text-align","center");
			EditShopEmailXsl.Style.Add("text-align","center");
			EmailOutputtab.Style.Add("text-align","center");

			test.Click +=new EventHandler(test_Click);
			querysettingsfile.Click +=new EventHandler(querysettingsfile_Click);
			
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void test_Click(object sender, EventArgs e)
		{
			try 
			{
				EmailOutput.Text = BusinessLogic.Store.GetEmailBody(int.Parse(orderid.Text));
			} 
			catch (Exception ex) {
					EmailOutput.Text = ex.ToString();
			}
		}

		private void querysettingsfile_Click(object sender, EventArgs e)
		{
			try 
			{
				QueryResult.Text = BusinessLogic.Store.QuerySettingsFileOutput(query.Text);
			} 
			catch (Exception ex) 
			{
				QueryResult.Text = ex.ToString();
			}
		}
	}
}
